import axios from 'axios'
import setting from './setting.js'
import router from '@/router/'
import { getToken } from '@/utils/auto'
const http = axios.create(setting.axios)

http.interceptors.request.use(function (config) {
    config.headers.Authorization = getToken()
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});

// 添加响应拦截器
http.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    if (response.config.url != '/account/login' && !getToken()) {
        return router.replace('/login')
    }
    return response;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});

export default http